<?php

//	Author: 	Aris Michail
//	Email:		std03055@di.uoa.gr
//	Purpose: 	Get all attributes of a category

require_once ("../DB/DB.php");
require_once ("../Frameworks/Objects/user.php");
require_once ("../Frameworks/Objects/category.php");
require_once ("../Frameworks/Objects/attribute.php");

function DB_category_getattributes($category, &$attributes)
{

    global $conn;

    // The name of the stored procedure
    $sp_name = "usp_category_getattributes";

    // The return variable
    $retval;

    // Get the values
    $categoryid = $category->GetId();

    // Create a new statement
    $stmt = mssql_init($sp_name, $conn);

    // Bind values
    mssql_bind($stmt, "RETVAL", $retval, SQLINT4, true, false, 1);
    mssql_bind($stmt, '@categoryid', $categoryid, SQLINT4, false, false, 1);

    // Execute the statement
    $status = mssql_execute($stmt);
    if (!$status)
        return DB_ERROR_GENERAL;
    else
    {
        $i = '0';
        while ($row = mssql_fetch_row($status))
        {
            $tmpattr = new Attribute();
             /* create a new attribute abject to add to the table */

            $tmpattr->SetName($row[0]);
             /* populate it's fields */
            $tmpattr->SetType($row[1]);
            $tmpattr->SetBestValue($row[2]);

            $attributes[$i] = $tmpattr;
             /* add it to the table */

            $i++;
            mssql_next_result($status);
        }
        return DB_OK;
    }
}

?>